<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%>

<div id="cc_products" class="easyui-layout" style="width:100%;height:100%;" fit="true">
    <div data-options="region:'center',title:'商品分类',split:true" style="width: 70%;height: 100%">
		<table id="categoryTableGrid" style="height: 100%"></table>
		 <div id="mm" class="easyui-menu" style="width:120px;">
	        <div onclick="openParentCategoryWin()" data-options="iconCls:'icon-add'">新增分类</div>
	        <div onclick="openAddCategoryWin()" data-options="iconCls:'icon-add'">修改分类</div>
	        <div onclick="removeIt()" data-options="iconCls:'icon-remove'">删除分类</div>
	        <div class="menu-sep"></div>
	    </div>
	</div>
	 <div data-options="region:'east',title:'分类属性',split:true" style="width: 30%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div>  

<script>
var toolbar = [
<se:hasPermissions actCode="ADD" >
{
	text:'分类录入',
    iconCls:'icon-add',
    handler:function(){
        var params = {};
    	$.pmsDialog({
    		id:"category_detail",
    		title:'分类新增',
    		href:'<c:url value="/views/jsp/category/category_saveOrUpdate_s.jsp"/>',
    		width:400,
    		params:params,
    		height:260
    	});
    }
},
</se:hasPermissions>
<se:hasPermissions actCode="DELETE" >
{
	text:'分类删除',
    iconCls:'icon-remove',
    handler:function(){
    	var node = $('#categoryTableGrid').treegrid('getSelected');
        if (node){
        	$.pmsAjax({
        		url:'<c:url value="/product/deleteEmBProductType.do"/>',
        		data:{"productTypeId":node.id},
        		success:function(data){
        			if(data.code=="200"){
        				alertShow("删除成功");
        				$('#categoryTableGrid').treegrid('remove', node.id);
        			}else{
        				alertError(data.result);
        			}
        		}
        	});
        }else{
    		alertWarning("请选择要删除的行!");
         }
    }
},
</se:hasPermissions>
{
	text:'【注：右键可操作】'
     
}];
//加载商品分类列表
var categoryTableGrid;
function initcategoryTableGrid(){
	categoryTableGrid = $('#categoryTableGrid').treegrid({
		    toolbar:toolbar,
			rownumbers: true,
			animate:true,
			collapsible:true,
			fitColumns: true,
			url:'<c:url value="/product/searchEmBProductType.do"/>?typeLevel=1',
			idField:'productTypeCode',//定义标识树节点的键名字段。必需。
			treeField:'productTypeName',
			columns:[[
				{field:'productTypeCode',title:'分类编号',align:'center'},
             	{field:'productTypeName',title:'分类名称'},
             	{field:'spell',title:'分类拼音码'},
				{field:'typeLevel',title:'分类等级'},
				{field:'parentTypeName',title:'上一级分类'},
				{field:'action',title:'操作',formatter:function(value,row){
					var str = "";
					<se:hasPermissions actCode="UPDATE" >
					str+= '<img class="iconImg ext-icon-application_edit" title="分类详情" onclick="updateCategoryWindow('+row.productTypeId+');">';
					</se:hasPermissions>
					/* str+= '<img class="iconImg ext-icon-application_edit" title="分类详情" onclick="openIcons();">'; */
					
					return str;
				}}
			]] ,
			onBeforeExpand:function(row,param){
				if(row)
				$(this).treegrid('options').url='<c:url value="/product/searchEmBProductType.do"/>?parentTypeId='+row.id;
			},
			onContextMenu:function(e, row){
				e.preventDefault();
		        $(this).treegrid('select', row.id);
		        $('#mm').menu('show',{
		                left: e.pageX,
		                top: e.pageY
		        });
			},
			onDblClickRow:function(index,row){
				openAddCategoryWin();
			}
	}); 
}
initcategoryTableGrid();


var idIndex = 100;
 
function removeIt(){
    var node = $('#categoryTableGrid').treegrid('getSelected');
    if (node){
    	$.pmsAjax({
    		url:'<c:url value="/product/deleteEmBProductType.do"/>',
    		data:{"productTypeId":node.id},
    		success:function(data){
    			if(data.code=="200"){
    				alertShow("删除成功");
    				$('#categoryTableGrid').treegrid('remove', node.id);
    			}else{
    				alertError(data.result);
    			}
    		}
    	});
    }else{
		alertWarning("请选择要删除的行!");
     }
}

//选择父节点后的新增
function  openParentCategoryWin(){
	$.pmsDialog({
		id:"category_detail",
		title:'分类新增',
		href:'<c:url value="/views/jsp/category/category_saveOrUpdate_s.jsp"/>',
		width:400,
		height:260
	});
}

 
//修改分类 
function updateCategoryWindow(productTypeId){
		var params = {};
	    params['productTypeId']=productTypeId;
	    $.pmsDialog({
			id:"category_detail",
			title:'分类修改',
			href:'<c:url value="/views/jsp/category/category_saveOrUpdate_s.jsp"/>',
			width:500,
			params:params,
			height:350
		});
}
function openIcons(){
	var params = {};
	params['productTypeId']=productTypeId;
    $.pmsDialog({
		id:"category_detail",
		title:'分类修改',
		href:'<c:url value="/css/sy/icons.jsp"/>',
		width:400,
		isIf:true,
		params:params,
		height:450
	});
}
function openAddCategoryWin(){
	//获取选中行
    var selectTree = $('#categoryTableGrid').treegrid("getSelected");
    var params = {};
    if(selectTree){
        params['productTypeName']=selectTree.productTypeName;
        params['productTypeId']=selectTree.productTypeId;
    } 
    $.pmsDialog({
		id:"category_detail",
		title:'分类修改',
		href:'<c:url value="/views/jsp/category/category_saveOrUpdate_s.jsp"/>',
		width:500,
		params:params,
		height:350
	});
}
</script>